package com.fyt.algorithm.Leecode.day4;

import java.util.Arrays;

public class MoveZeroes
{  //我的方案
  /*  public static void moveZeroes(int[] nums) {
        int left = 0;
        int right = left + 1;
        while (right <= nums.length - 1 && left < nums.length - 1 && left <= right) {
            while (left < nums.length - 1&&nums[left] != 0)
                left++;
            while (right <= nums.length - 1&&nums[right] == 0)
                right++;

            if(left>right) break;
            if(right>nums.length-1) break;
            int temp = 0;
            temp = nums[left];
            nums[left] = nums[right];
            nums[right] = temp;


        }

        System.out.println(Arrays.toString(nums));
    }*/

    //chatGPT方案
    public static void moveZeroes(int[] nums){
        int left=0;
        int right=0;
        while (right<=nums.length-1){
           if(nums[right]!=0){

               int temp;
               temp=nums[right];
               nums[right]=nums[left];
               nums[left]=temp;
               left++;
           }
            right++;
        }

        System.out.println(Arrays.toString(nums));


    }


    public static void main(String[] args) {
        int []arr={1,2,3,1};
        moveZeroes(arr);
    }

}
